/**
 * copyright 2014 by luobiliu
 *
 * @file:       PunchStaticData.cpp
 * @author:     luobiliu
 * @version:    1.0
 * @date:       2014-8-4
 *
 */

#include "PunchStaticData.h"

USING_NS_CC;
using namespace std;

#define STATIC_DATA_PATH "static_data.plist"

static PunchStaticData* _sharedStaticData = NULL;
PunchStaticData* PunchStaticData::sharedStaticData()
{
    if(_sharedStaticData == NULL){
        _sharedStaticData = new PunchStaticData();
        _sharedStaticData->init();
    }
    return _sharedStaticData;
}
PunchStaticData::PunchStaticData()
{
    _staticDataPath = STATIC_DATA_PATH;
}
PunchStaticData::~PunchStaticData()
{
    CC_SAFE_RELEASE_NULL(_dictionary);
}
bool PunchStaticData::init()
{
    _dictionary = CCDictionary::createWithContentsOfFile(_staticDataPath.c_str());
    CC_SAFE_RETAIN(_dictionary);
    return true;
}
const char* PunchStaticData::stringFromKey(string key)
{
    return _dictionary->valueForKey(key)->getCString();
}
int PunchStaticData::intFromKey(string key)
{
    return _dictionary->valueForKey(key)->intValue();
}
float PunchStaticData::floatFromKey(string key)
{
    return _dictionary->valueForKey(key)->floatValue();
}
bool PunchStaticData::booleanFromKey(string key)
{
    return _dictionary->valueForKey(key)->boolValue();
}
cocos2d::CCPoint PunchStaticData::pointFromKey(string key)
{
    return CCPointFromString(_dictionary->valueForKey(key)->getCString());
}
cocos2d::CCRect PunchStaticData::rectFromKey(string key)
{
    return CCRectFromString(_dictionary->valueForKey(key)->getCString());
}
cocos2d::CCSize PunchStaticData::sizeFromKey(string key)
{
    return CCSizeFromString(_dictionary->valueForKey(key)->getCString());
}
void PunchStaticData::purge()
{
    CC_SAFE_RELEASE_NULL(_sharedStaticData);
}

